﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.IO;
using System.Xml.Linq;

namespace InfoPick.UI
{
    public class AppGlobal
    {
        private static readonly string path = string.Format("{0}{1}", AppDomain.CurrentDomain.BaseDirectory, ConfigurationManager.AppSettings["XmlDataFile"]);
        public static string Path
        {
            get
            {
                return path;
            }
        }

        public static void InitXmlData()
        {
            FileInfo fi = new FileInfo(path);
            
            if (!fi.Directory.Exists)
            {
                Directory.CreateDirectory(fi.DirectoryName);
            }
            if (!fi.Exists)
            {
                XDocument xdoc = new XDocument();

                XElement root = new XElement("Data");
                XElement mgws = new XElement("MGWS");
                mgws.Add(new XAttribute("Default", ""));
                root.Add(mgws);

                XElement mscs = new XElement("MSCS");
                mscs.Add(new XAttribute("Default", ""));
                root.Add(mscs);

                XElement mgw = new XElement("MGWPath");
                mgw.Add(new XAttribute("Last", ""));
                root.Add(mgw);

                XElement msc = new XElement("MSCPath");
                msc.Add(new XAttribute("Last", ""));
                root.Add(msc);

                XElement excel = new XElement("ExcelPath");
                excel.Add(new XAttribute("Last", ""));
                root.Add(excel);

                xdoc.Add(root);

                xdoc.Save(path);
            }
        }
    }
}
